'''
ExperimentGroup Use Case Tests

1) Make a control group inside experiment (check value)
2) Edit control group (check values)
3) Delete control group
'''

from interactive import *

#1)

css("#ColonyView")
linkpart("EPO").click()
twait()

css("#ColonyMenu")
linkpart("Experiments").click()
twait()

css("#ExperimentView")
linkpart("Alpha").click()
twait()

New()
twait()

css("#ExperimentGroupDetail")
css("#ExperimentGroupDetail #Name").send_keys("Test Experiment Group")
css("#ExperimentGroupDetail #AgeDaysLowerLimit").send_keys("4")
css("#ExperimentGroupDetail #AgeDaysUpperLimit").send_keys("7")
Select(css("#ExperimentGroupDetail #Gender")).select_by_value("M")
Select(css("#ExperimentGroupDetail #GenotypeID")).select_by_value("2")
css("#ExperimentGroupDetail #MouseQuantity").clear()
css("#ExperimentGroupDetail #MouseQuantity").send_keys("123")
css("#ExperimentGroupDetail #Comment").send_keys("This is an experiment group test")
Done()
twait()

#css("#ExperimentGroupView")
#linkpart("Alpha").click()
#twait()

css("#ExperimentGroupView")
Edit()
linkpart("Test Experiment Group").click()
twait()

css("#ExperimentGroupDetail")
assert(css("#ExperimentGroupDetail #Name").get_attribute("value") == "Test Experiment Group")
assert(css("#ExperimentGroupDetail #AgeDaysLowerLimit").get_attribute("value") == "4")
assert(css("#ExperimentGroupDetail #AgeDaysUpperLimit").get_attribute("value") == "7")
assert(Select(css("#ExperimentGroupDetail #Gender")).first_selected_option.text == "Male")
assert(Select(css("#ExperimentGroupDetail #GenotypeID")).first_selected_option.text == "C57BL")
assert(css("#ExperimentGroupDetail #MouseQuantity").get_attribute("value") == "123")
assert(css("#ExperimentGroupDetail #Comment").get_attribute("value") == "This is an experiment group test")

#2)
Edit()
css("#ExperimentGroupDetail #Name").clear()
css("#ExperimentGroupDetail #Name").send_keys("Altered Test Experiment Group")
css("#ExperimentGroupDetail #AgeDaysLowerLimit").clear()
css("#ExperimentGroupDetail #AgeDaysLowerLimit").send_keys("34")
css("#ExperimentGroupDetail #AgeDaysUpperLimit").clear()
css("#ExperimentGroupDetail #AgeDaysUpperLimit").send_keys("45")
Select(css("#ExperimentGroupDetail #Gender")).select_by_value("F")
Select(css("#ExperimentGroupDetail #GenotypeID")).select_by_value("1")
css("#ExperimentGroupDetail #MouseQuantity").clear()
css("#ExperimentGroupDetail #MouseQuantity").send_keys("22")
css("#ExperimentGroupDetail #Comment").clear()
css("#ExperimentGroupDetail #Comment").send_keys("This is an experiment group test")
Done()
twait()

#css("#ExperimentView")
#linkpart("Alpha").click()
#twait()

css("#ExperimentGroupView")
Edit()
linkpart("Altered Test Experiment Group").click()
twait()

css("#ExperimentGroupDetail")
assert(css("#ExperimentGroupDetail #Name").get_attribute("value") == "Altered Test Experiment Group")
assert(css("#ExperimentGroupDetail #AgeDaysLowerLimit").get_attribute("value") == "34")
assert(css("#ExperimentGroupDetail #AgeDaysUpperLimit").get_attribute("value") == "45")
assert(Select(css("#ExperimentGroupDetail #Gender")).first_selected_option.text == "Female")
assert(Select(css("#ExperimentGroupDetail #GenotypeID")).first_selected_option.text == "Epo fl/fl")
assert(css("#ExperimentGroupDetail #MouseQuantity").get_attribute("value") == "22")
assert(css("#ExperimentGroupDetail #Comment").get_attribute("value") == "This is an experiment group test")

#3)

Back()
twait()

#css("#ExperimentView")
#linkpart("Alpha").click()
#twait()


Edit()
driver.execute_script("return $('#ExperimentGroupView li').has (':contains(\"Altered Test Experiment Group\")').find('a').has('.ui-icon-delete')[0]").click() 
alert = driver.switch_to_alert()
#FIXME
assert(alert.text == "Are you sure you wish to delete Altered Test Experiment Group?")
alert.accept()

driver.quit()
